<?php 
if (!defined('BASEPATH')){
	exit('No direct script access allowed');
}

/**
 * customerAssess Controller
 * Build by Phuc Nguyen
 * Contact : nguyenvanphuc0626@gmail.com
 */

class CustomerAssess extends BACKEND_Controller {
	public function __construct() {
		parent::__construct();
		$this->load->language('customerAssess');
		$this->load->language('button');
		if($this->database_connect_status){
			$this->load->model('customerAssess_model');
			$this->set_controller('customerAssess');
			$this->set_model($this->customerAssess_model);
		}

                $this->load->library('bookinglib');
                $this->bookinglib = new bookinglib();
	}
        
        private function menuTop(){
            $this->load->model('stats_model');
            $user_info                          = $this->stats_model->get_user_info($this->stats_model->get_user_id());
            $this->view_data['role_by_group']   = $user_info['role_list'];
            $this->view_data['username']        = $user_info['username'];
            return $this->view_data;
        }
        
        private function direct(){
            $checkDirect = $_SERVER['HTTP_REFERER'];
            if(!isset($checkDirect)){
                redirect(base_url());
            }
        }
        
        
        public function updateStatus(){
            if($this->input->server('REQUEST_METHOD')=='POST'){
                $result = $this->customerAssess_model->updateStatus(array('customerID'=>$this->input->post('customerID'),'status'=>$this->input->post('status')));
                echo $result;exit;
            }
        }
        
        protected function update($params=NULL){
            $this->load->model('customerAssess_model');
            $this->load->model('language_model');

            if(isset($params)){
                    $customerAssess_model	= $this->customerAssess_model->find_by(array('customerID' => $params,'status'=>'0'));
                    if(empty($customerAssess_model)){
                       echo '<script>alert("'.$this->lang->line('used_calling').'");window.top.location.href="/auth/customerAssess/";</script>';exit;
                    } else {
                        $this->load->model("listcustomers_model");
                        $info_user                                                      = $this->listcustomers_model->find_by(array('customerID' => $params));
                        $customerAssess_model[0]->name                                  = $info_user[0]->name;
                        $customerAssess_model[0]->phone                                 = json_decode($info_user[0]->phone);
                        $this->view_data['customerAssess']                              = $customerAssess_model[0];
                        $this->customerAssess_model->updateStatus(array('customerID'=>$customerAssess_model[0]->customerID,'status'=>'1'));
                    }
            }

            $this->view_data['js'] = array(
                            base_url().'static/templates/backend/js/main.js'
            );
            $this->view_data['css'] = array(
            );
            
            $this->load->view('auth/customerAssess/edit', $this->view_data);
	}
        
        public function updateInfo(){
            
            $this->direct();//prevent direct
            if($this->input->server('REQUEST_METHOD')=='POST'){
                $this->view_data["customerAssess"]                              = new stdClass();
                $this->view_data["customerAssess"]->phone_callstatus            = $this->input->post('phone_callstatus');
                $this->view_data["customerAssess"]->note_customers              = $this->input->post('note_customers');
                
                $this->view_data["customerAssess"]->phone_real                  = ($this->input->post('phone_real'))?$this->input->post('phone_real'):'';
                $this->view_data["customerAssess"]->customer_price              = ($this->input->post('customer_price'))?$this->input->post('customer_price'):'';
                
                $this->view_data["customerAssess"]->owner                       = $this->session->userdata['user_id'];
                $this->view_data["customerAssess"]->agent_code                  = $this->session->userdata['agent_code'];
                $this->view_data["customerAssess"]->lastupdated                 = date("Y-m-d H:i:s",time());

                $this->customerAssess_model->updateInfo($this->view_data["customerAssess"],array('customerID' => $this->input->post('customerID')));
                unset($this->view_data["customerAssess"]);
                die('1');
            }
            die("");
        }
        
}

/* End of file customerAssess.php */
/* Location: ./application/controllers/auth/customerAssess.php */